package cn.jji8.QSGUI.Gui.Goods;

import cn.jji8.QSGUI.quick.tool.ConfgTool;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.maxgamer.quickshop.shop.Shop;

public class implement extends Decorate implements Goods{
    String sellBuyNumber = null;
    boolean close = true;
    /**
     * 在类别构造出来后一定要调用一次的方法
     *
     * @param shop 对应的商店
     * @param yml  对应的配置文件
     * @param key  自己对应的key
     */
    @Override
    public void setGoods(Shop shop, YamlConfiguration yml, String key) {
        super.setGoods(shop,yml,key);
        sellBuyNumber = ConfgTool.getString(yml,key,"点击强制玩家发送消息",null,false);
        close = ConfgTool.getBoolean(yml,key,"点击后关闭gui",true,false);
    }

    /**
     * 获取要在箱子中显示的物品
     *
     * @param player
     */
    @Override
    public ItemStack getItemStack(Player player) {
        return super.getItemStack(player);
    }

    /**
     * 玩家点击此物品时调用的方法
     *
     * @param a
     */
    @Override
    public void click(InventoryClickEvent a) {
        if(sellBuyNumber!=null){
            HumanEntity humanEntity = a.getWhoClicked();
            if(humanEntity instanceof Player){
                ((Player)humanEntity).chat(sellBuyNumber);
                if(close){
                    humanEntity.closeInventory();
                }
            }
        }
    }
}
